#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

lockfile=$(grep lockfile /etc/slim.conf |tr -s " " | cut -d" " -f2)
pid=$(pidof -o %PPID /usr/bin/slim)

case "$1" in
  start)
    if [ "$cn" ="y" ] || [ "${LOCALE%_*}x" = "zhx" ]; then
	stat_busy "正在启动 SLIM登录管理器"
    else
	stat_busy "Starting Simple Login Manager"
    fi
    [ -z "$pid" ] && /usr/bin/slim -d >/dev/null 2>&1
    if [ $? -gt 0 ]; then
      stat_fail
    else
      add_daemon slim
      stat_done
    fi
    ;;
  stop)
    if [ "$cn" ="y" ] || [ "${LOCALE%_*}x" = "zhx" ]; then
	stat_busy "正在关闭 SLIM登录管理器"
    else
	stat_busy "Stopping Simple Login Manager"
    fi
    rm -f $lockfile
    [ ! -z "$pid" ]  && kill $pid >/dev/null 2>&1
    if [ $? -gt 0 ]; then
      stat_fail
    else
      rm_daemon slim
      stat_done
    fi
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
  *)
    echo "usage: $0 {start|stop|restart}"  
esac

exit 0
